import router from './router.js'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import msggage from '@/utils/ActionMessage.js'
import store from '@/store/index.js'
let whiteList=['/login','/xiaohu']
router.afterEach((to, from) => {
	NProgress.done()
});
router.onError((error) => {
	NProgress.done();
	msggage.error(error.message);
});
router.beforeEach(async (to, from, next) => {
	const token=store.getters._token
	NProgress.start()
	document.title = to.meta.title ? `mango-${to.meta.title}`:''
	if(whiteList.includes(to.path)){
		next();
		return false;
	} else {
		if(!token){
			next({
				path: '/login'
			});
			return false;
		}
	}
	
	//整页路由处理
	if(to.meta.fullpage){
		to.matched = [to.matched[to.matched.length-1]]
	}
	next();
});